//d[R][G] = 0
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;

int n,m,k;
int a[100005],c[100005];
int x[5];
bool d[65540];

inline int solve(int index) //first index numbers,
{
	int res = 0;
	int k2 = ceil(log2(c[index]));
	for(int i=1;i<=k2;++i)
	{
		if(a[k2]>=k2)
			res += i;
	}
	return res;
}

int main()
{
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	scanf("%d%d",&n,&m);
	k = ceil(log2(n));
	memset(a,0x3f,sizeof(a));
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for(int i=1;i<=m;++i)
		scanf("%d",&c[i]);
	for(int i=1;i<=pow(2,k);++i)
	{
		string s;
		cin >> s;
		for(int j=1;j<=(int)s.size();++j)
		{
			if(i==1 && s[j]=='1')
				d[j] = 1;
		}
	}
	int T;
	scanf("%d",&T);
	for(int i=1;i<=4;++i)
		scanf("%d",&x[i]);
	for(int i=1;i<=c[1];++i)
		a[i] ^= x[i%4];
	printf("%d\n",solve(1));
	fclose(stdin);
	fclose(stdout);
	return 0;
}
